﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Web.UI.WebControls;
using BLL;
using Model;
using ZedGraph;


public partial class StatisticData_ProductionStatistic_ProductionbyProductType : System.Web.UI.Page
{
    private DateTime dt1
    {
        get { return DateTime.Parse(ViewState["starttime"].ToString()); }
        set { ViewState["starttime"] = value; }
    }
    private DateTime dt2
    {
        get { return DateTime.Parse(ViewState["stoptime"].ToString()); }
        set { ViewState["stoptime"] = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        dt1 = DateTime.Parse(this.TextBox1.Value.Trim());
        dt2 = DateTime.Parse(this.TextBox2.Value.Trim());
        BindProductType_Q();
        this.ZedGraphWeb1.Visible = true;
    }

    private void BindProductType_Q()
    {
        Test_Q t_q = new Test_Q();
        this.GridView1.DataSource = t_q.GetProductType_Q(dt1, dt2);
        GridView1.DataBind();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GridView1.PageIndex = e.NewPageIndex;
        BindProductType_Q();
    }

    protected void ZedGraphWeb1_RenderGraph(ZedGraph.Web.ZedGraphWeb webObject, System.Drawing.Graphics g, ZedGraph.MasterPane pane)
    {
        int i = 0;
        int j = 0;
        Test_Q t_qt = new Test_Q();
        List<ProductType_QInfo> t_qs = (List<ProductType_QInfo>)t_qt.GetProductType_Q(dt1, dt2);

        GraphPane myPane = pane[0];

        myPane.Title.Text = "各产品类型产能情况统计";
        myPane.XAxis.Title.Text = "产品类型";
        myPane.YAxis.Title.Text = "产能情况";

        //创建曲线
        PointPairList list = new PointPairList();
        foreach (ProductType_QInfo t_q in t_qs)
        {
            double y = (double)t_q.Quantity;
            int x = i;
            i++;
            list.Add(x, y);
        }
        //LineItem myCurve = myPane.AddCurve("", list, Color.Green, SymbolType.Square);
        //myCurve.Line.IsSmooth = true;
        myPane.AddBar("合格腔体数", list, Color.Green);

        PointPairList list1 = new PointPairList();
        foreach (ProductType_QInfo t_q in t_qs)
        {
            double y = (double)t_q.Total;
            int x = i;
            i++;
            list1.Add(x, y);
        }
        myPane.AddBar("测试次数", list1, Color.Blue);

        string[] labels = new string[t_qs.Count];
        //给x轴上的每一个间隔点加上说明文字
        foreach (ProductType_QInfo t_q in t_qs)
        {
            labels[j] = t_q.ProductTypeID;
            j++;
        }

        myPane.XAxis.Scale.TextLabels = labels; //这里设置的是TextLabels属性，所以下面x轴的类型必须也设置为Text   

        //设置x轴的样式
        myPane.XAxis.Type = AxisType.Text;
        MyGraphStyle.BuildbarGraphStyle(myPane);

        pane.AxisChange(g);
    }
}
